package br.com.jw.dao;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.ArrayList;

import br.com.jw.modelo.Cliente;
import br.com.jw.modelo.Menu;
import android.content.Context;

public class MenuDao {
	String[] result;
	Context context;
	int resultado = 0;
	boolean aux = false;

	public MenuDao(Context context) {
		this.context = context;
	}

	public ArrayList<Menu> getListaMenus() {
		try {
			Socket socket = new Socket("10.0.2.2", 7777);
			DataInputStream in = new DataInputStream(socket.getInputStream());
			DataOutputStream out = new DataOutputStream(
					socket.getOutputStream());
			out.writeUTF("menus");
			out.writeUTF("listarMenus");
			out.flush();
			result = in.readUTF().split(",");

			ArrayList<Menu> listaMenus = new ArrayList<Menu>();
			for (int i = 0; i < result.length; i += 2) {

				listaMenus.add(new Menu(
						Integer.parseInt(result[i]),						
						result[i + 1]));
			}

			out.close();
			in.close();
			socket.close();
			return listaMenus;

		} catch (Exception e) {
			e.printStackTrace();
			// mostra os erros no log
			e.getMessage();
			return null;
		}
	}

}
